package com.visec.hdy.transmission.ftp.config;

import java.util.Map;

import com.visec.hdy.config.ParameterCV;
import com.visec.hdy.utils.ParameterHandle;

public class FtpModelCV implements ParameterCV<FtpModel> {

	private String charset = "utf-8";
	private String ftpCharset = "iso-8859-1";
	private int port = 21;

	private Map<String, String> data;

	/**
	 * charset=fcharset;ip=fip;port=fport;user=fuser;password=fpassword
	 * 
	 * @param m
	 */
	@Override
	public void setParams(Map<String, String> m) {
		// TODO Auto-generated method stub
		if (m.containsKey("-fcharset"))
			charset = m.get("-fcharset");
		if (m.containsKey("-ftpCharset"))
			ftpCharset = m.get("-ftpCharset");
		if (m.containsKey("fport")) {
			port = Integer.parseInt(ParameterHandle.testNumber(data.get("-fport")));
		}
		data = m;
	}

	@Override
	public FtpModel getParameter() {
		// TODO Auto-generated method stub
		return new FtpModel(ParameterHandle.testIp(data.get("-fip")), port, data.get("-fuser"), data.get("-fpassword"),
				charset, ftpCharset);
	}

}
